/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.bezrabotnih.cabinet.client.ui;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.bezrabotnih.cabinet.client.ui.ProviderJobsView.Presenter;
import net.bezrabotnih.client.managed.request.JobProxy;
import net.bezrabotnih.client.managed.request.UserAccountProxy;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.OpenEvent;
import com.google.gwt.event.logical.shared.OpenHandler;
import com.google.gwt.place.shared.Place;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Sample implementation of {@link PerformerJobsView}.
 */
public class PerformerJobsViewImpl extends Composite implements PerformerJobsView {

	interface Binder extends UiBinder<Widget, PerformerJobsViewImpl> {
	}
	
	private static final Binder binder = GWT.create(Binder.class);

	@UiField VerticalPanel jobsStackPanel;
	@UiField HTML title;
	
	Presenter listener;
	
	private HashMap<String, PerformerJobBlockView> blockViews;

	public PerformerJobsViewImpl() {
		initWidget(binder.createAndBindUi(this));
		blockViews=new HashMap<String, PerformerJobBlockView>();
	}

	

	@Override
	public void setPresenter(Presenter listener) {
		this.listener = listener;
	}
	
	public void setTitle(String title){
		this.title.setHTML("<h3>"+title+"</h3>");
		
	}

    public void addJobBlock(net.bezrabotnih.cabinet.client.ui.PerformerJobBlockView.Presenter listener,final String jobId,String jobName,String jobType,String provider,boolean isHourly,Date startDate, Date deadline, Integer price,String description,boolean applied,boolean winner){
    	PerformerJobBlockView blockView=new PerformerJobBlockView(listener, jobId, jobName, jobType, provider, isHourly, startDate, deadline, price, description, applied,winner);
    	jobsStackPanel.add(blockView);
    	blockViews.put(jobId, blockView);
    }

	
	
	



	@Override
	public void setProviderName(String name,String jobId) {
		blockViews.get(jobId).setProviderName(name);
		
	}

	public void setApplicationSuccessView(String jobId) {
		PerformerJobBlockView blockView=blockViews.get(jobId);
		if (blockView!=null) blockView.setApplicationSuccessView();
	}




	public void setApplicationFailureView(String jobId) {
		PerformerJobBlockView blockView=blockViews.get(jobId);
		if (blockView!=null) blockView.setApplicationFailureView();
	}




	public void setApplicationCancelSuccessView(String jobId) {
		PerformerJobBlockView blockView=blockViews.get(jobId);
		if (blockView!=null) blockView.setApplicationCancelSuccessView();
		
	}




	public void setApplicationCancelFailureView(String jobId) {
		PerformerJobBlockView blockView=blockViews.get(jobId);
		if (blockView!=null) blockView.setApplicationCancelFailureView();
		
	}



}
